package com.hhxy.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * 测试定时刷新并跳转的功能
 * 目的：属性使用setHeader实现页面的自动刷新和跳转
 * @author ghp
 * @date 2022/9/13
 */
@WebServlet("/refreshServlet")
public class RefreshServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        /*测试一：*/
        //2s后刷新并跳转到黑马官网
//        response.setHeader("Refresh","2;URL=http://www.itcast.cn");

        /*--------------------------------------------------------------*/

        /*测试二：*/
        //每隔3s刷新当前页面
        response.setHeader("Refresh","3");
        //输出当前时间
        response.getWriter().println(new Date());

    }
}